<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Sugar</title>
  </head>

  <body>
    <script>
      const data = { aa: 11, bb: 22 }
      // aa=11&bb=22
      // 功能1：把对象转换成查询参数对象
      const obj = new URLSearchParams(data)
      console.log(obj.toString())
      const aa = obj.get('aa')
      console.log(aa)

      const query = '?id=212'
      // 功能2：把查询字符串转换成查询参数对象（目的：更方便获取查询参数的值）
      const obj2 = new URLSearchParams(query)
      console.log(obj2) // {}
      const id = obj2.get('id') //
      console.log(id)
    </script>
  </body>
</html>
